<?php

require_once 'Config.php';
require_once 'alipay-sdk/aop/AopClient.php';
require_once 'alipay-sdk/aop/request/AlipayOpenAuthTokenAppQueryRequest.php';

class QueryAuth extends Config{
    public function request(){
        if(isset($_POST['app_auth_token'])){
            $app_auth_token=$_POST['app_auth_token'];

            $aop = new AopClient ();
            $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
            $aop->appId = $this->app_id;
            $aop->rsaPrivateKey = $this->privateKey;
            $aop->alipayrsaPublicKey=$this->publicKey;
            $aop->apiVersion = '1.0';
            $aop->signType = 'RSA2';
            $aop->postCharset='UTF-8';
            $aop->format='json';
            $request = new AlipayOpenAuthTokenAppQueryRequest ();
            $request->setBizContent(json_encode([
                'app_auth_token'=>$app_auth_token
            ]));
            $result = $aop->execute ($request);
            $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
            $resultCode = $result->$responseNode->code;
            if(!empty($resultCode)&&$resultCode == 10000){
                file_put_contents($this->queryDataPath,json_encode($result));
                echo "<pre>";print_r($result);echo "<pre>";
            } else {
                echo "失败";
            }
        }
    }
}

(new QueryAuth())->request();